package fun.linze.wallpaperwebsite.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import fun.linze.wallpaperwebsite.dao.wallpaper.Tags;
import fun.linze.wallpaperwebsite.domain.TWallpaperTag;
import fun.linze.wallpaperwebsite.service.TWallpaperTagService;
import fun.linze.wallpaperwebsite.mapper.TWallpaperTagMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author wangy
* @description 针对表【t_wallpaper_tag(壁纸与标签的关联表)】的数据库操作Service实现
* @createDate 2025-06-29 10:20:46
*/
@Service
public class TWallpaperTagServiceImpl extends ServiceImpl<TWallpaperTagMapper, TWallpaperTag>
    implements TWallpaperTagService{

    @Override
    public List<Integer> getTagIdsByWallpaperId(Long wallpaperId) {
        QueryWrapper<TWallpaperTag> queryWrapper = new QueryWrapper<>();
        // 1. 指定查询条件：wallpaper_id = ?
        queryWrapper.eq("wallpaper_id", wallpaperId);
        // 2. 指定只查询 tag_id 字段，提高效率
        queryWrapper.select("tag_id");

        // 3. 执行查询
        List<TWallpaperTag> list = baseMapper.selectList(queryWrapper);

        // 4. 从对象列表中提取 tagId 字段，并返回
        return list.stream()
                .map(TWallpaperTag::getTagId)
                .collect(Collectors.toList());
    }

    @Override
    public List<Long> getWallpaperIdsByTagId(Integer tagId) {
        QueryWrapper<TWallpaperTag> queryWrapper = new QueryWrapper<>();
        // 1. 指定查询条件：tag_id = ?
        queryWrapper.eq("tag_id", tagId);
        // 2. 指定只查询 wallpaper_id 字段
        queryWrapper.select("wallpaper_id");

        // 3. 执行查询
        List<TWallpaperTag> list = baseMapper.selectList(queryWrapper);

        // 4. 从对象列表中提取 wallpaperId 字段，并返回
        return list.stream()
                .map(TWallpaperTag::getWallpaperId)
                .collect(Collectors.toList());
    }
}




